// pages/cates/cates.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    items: [
      { value: "USA", name: "美国" },
      { value: "CHN", name: "中国", checked: "true" },
      { value: "BRA", name: "巴西" },
      { value: "JPN", name: "日本" },
      { value: "ENG", name: "英国" },
      { value: "FRA", name: "法国" },
    ],
    xuan: true,
    mc: "选中",
    pickerHidden: true,
    chosen: "",
    array: ["美国", "中国", "巴西", "日本"],
    index: 0,
    num: 0,
    move: "",
    animation: null as any , // 给组件的animation属性使用的
  }, // data里面声明的数据只能通过this.setData({})进行赋值操作，因为setData具备渲染更新组件的功能。具备响应式。
  animationObj: {} as WechatMiniprogram.Animation, // data的外面也可以声明变量，通过this.animationObj进行赋值和取值的操作，这里保存的数据一般都是不需要在页面中展示的数据，不需要它具备响应式功能。
  onLoad() {
    //1.创建动画实例对象
    this.animationObj = wx.createAnimation({
      duration: 1000, //时间
      transformOrigin: "ease-in-out",
    });
    //2.给动画实例绑定动画效果
    this.animationObj
      .translateX(200)
      .step()
      .rotate(360)
      .step()
      .scale(1.5)
      .step();
      //3.将动画实例暴露给组件的animation属性

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: "checkbox",
      path: "page/component/pages/checkbox/checkbox",
    };
  },
  checkboxChange(e: any) {
    console.log("checkbox发生change事件，携带value值为：", e.detail.value);

    const items = this.data.items;
    const values = e.detail.value;
    for (let i = 0, lenI = items.length; i < lenI; ++i) {
      (items[i].checked as any) = false;

      for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (items[i].value === values[j]) {
          (items[i].checked as any) = true;
          break;
        }
      }
    }

    this.setData({
      items,
    });
  },
  jt(e: any) {
    console.log(e.detail.value);
    let a = e.detail.value.length;
    if (a) {
      console.log("有");
      this.setData({
        mc: "选中",
      });
    } else {
      this.setData({
        mc: "未选中",
      });
    }
  },

  pickerCancel() {
    this.setData({
      pickerHidden: true,
    });
  },

  pickerShow() {
    this.setData({
      pickerHidden: false,
    });
  },

  formSubmit(e: any) {
    console.log("form发生了submit事件，携带数据为：", e.detail.value);
  },

  formReset(e: any) {
    console.log("form发生了reset事件，携带数据为：", e.detail.value);
    this.setData({
      chosen: "",
    });
  },
  bindPickerChange: function (e: any) {
    console.log("picker发送选择改变，携带值为", e.detail.value);
    this.setData({
      index: e.detail.value,
    });
  },
  //动画
  dong() {
    this.setData({
      move: "sart",
    });
  },
  hua(){
    this.setData({
  // 3. 将动画实例暴漏给组件的animation属性
  animation:this.animationObj.export()
    })
      
  }
});
